<layout name="Layout/layout" />

<div id="wrapper">
    <div class="col-md-2">
        <include file="Layout:left-menubar" />
    </div>

    <div class="col-md-10">
    <!-- Page Content -->
    <div id="page-content-wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <h1>考点选择</h1>
                    <div class="table-responsive ">
                        <table class="table table-bordered table-hover">
                            <tr>
                                <th>考点</th>
                                <th>报考专业</th>
                                <th>报名开始时间</th>
                                <th>报名结束时间</th>
                                <th>报名</th>
                            </tr>
                            <foreach name="examcenterlist" item="v">
                                <tr>
                                    <td>{$v.name}</td>
                                    <td>
                                        <?php
                                            foreach(explode(',', $v['majors']) as $vo){
                                                if($vo!=0){
                                                ?>
                                                <label>
                                                    <input type="checkbox" name="major[]" value="{$vo}"> {:showMajorName($vo, $majornodes)}
                                                </label>
                                                <?php
                                            }
                                            }
                                            ?>
                                    </td>
                                    <td>
                                        {:date('Y-m-d', $v['start_time'])}
                                    </td>
                                    <td>
                                        {:date('Y-m-d', $v['end_time'])}
                                    </td>
                                    <td>
                                        <button examcenterid={$v['id']} type="button" class="btn btn-primary btn-enroll">报名</button>
                                    </td>
                                </tr>
                            </foreach>
                        </table>
                    </div>
                    <hr />
                    <h1>已选择的考试</h1>
                    <div class="table-responsive ">
                        <table class="table table-bordered table-hover">
                            <tr>
                                <th>项目ID</th>
                                <th>考点</th>
                                <th>报考专业</th>
                                <th>报名时间</th>
                                <th>最后操作时间</th>
                                <th>是否缴费</th>
                                <th>操作</th>
                            </tr>
                            {:trace($enrolllist)}
                            <foreach name="enrolllist" item="v">
                                <tr>
                                    <td>{$v['id']}</td>
                                    <td>{:getExamcenterName($v['examcenter'])}</td>
                                    <td>{:getMajorNames($v['major'])}</td>
                                    <td>{:formatDate($v['enrolltime'])}</td>
                                    <td>{:formatDate($v['uptime'])}</td>
                                    <td>{:ispayed($v['ispayed'])}</td>
                                    <td>

                                        <?php if(!$v['ispayed']){ ?>
                                            <button enrollid={$v['id']} type="button" class="btn btn-danger btn-delete">取消</button>
                                            <button type="button" class="btn btn-primary query">前往缴费</button>
                                            <?php }else{ ?>
                                                <p class="text-success">缴费成功</p>
                                                <?php } ?>
                                    </td>
                                </tr>
                            </foreach>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /#page-content-wrapper -->
    </div>
</div>
<!-- /#wrapper -->
<!-- Modal -->
<div class="modal fade" id="confirmModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">确认你要提交的信息</h4>
      </div>
      <div class="modal-body">
          <div>你选择的考点是：<span id="provinceModal">四川</span></div>
          <div id="majorModal">你选择的专业是：<span >美术类</span></div>
      <div>你需要缴纳的费用是<span id="numofvalue">0</span>元</div>
          <p class="text-danger">缴费后你将不能更改考点以及专业！</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" id="submit">确认并前往缴费</button>
      </div>
    </div>
  </div>
</div>
<script>
window.onload = function(){
    $('#submit').click(function(){
        var enrollid = $(this).attr('enrollid');
        var numofvalue = $('#numofvalue').text();
         //alert('支付平台暂未开通，请及时关注西南大学招就处本科招生网相关通知');
         window.open("{:U('Home/Pay/pay')}?enrollid=" + enrollid + "&numofvalue=" + numofvalue);
    });
    $('input').iCheck({
        checkboxClass: 'icheckbox_minimal-orange',
        radioClass: 'iradio_minimal-orange',
        increaseArea: '20%' // optional
    });
    $('.query').click(function(){
        var enrollid = $(this).parent().siblings().first().text();
        $('#majorModal').text('你选择的专业是：');
        $('#majorModal').append($(this).parent().siblings().eq(2).text());
        $('#provinceModal').text($(this).parent().siblings().eq(1).text());
        $('#submit').attr('enrollid', enrollid);
        $.post("{:U('Home/Pay/getValue')}",{
            enrollid: enrollid
        },function(data, state){
            console.log(data);
            if(data.opstatus != 'error'){
                $('#numofvalue').text(data.numofvalue);
                $('#confirmModal').modal();
            }
            else{
                alert('无法读取缴费金额，请刷新页面重试');
            }
        });

    });
    $('.btn-enroll').click(function(){
        var examcenterid = $(this).attr('examcenterid');
        var checkboxes = [];
        $(this).parent().siblings().eq(1).children().each(function(){
            if($(this).find('input').is(':checked')){
                checkboxes.push($(this).find('input').val());
            }
        });
        if(checkboxes.length == 0){
            alert('请输入专业后再继续填写');
        }
        $.post("{:U('Home/Project/enroll')}",
        {
            examcenterid: examcenterid,
            majors: checkboxes
        },
        function(data, state){
            window.location.href="{:U('Home/Index/select')}";
        });
    });
    $('.btn-delete').click(function(){
        var enrollid = $(this).attr('enrollid');
        $.post("{:U('Home/Project/delete')}",
        {
            enrollid: enrollid
        },
        function(data, state){
            window.location.href="{:U('Home/Index/select')}";
        });
    });
}
</script>
